package com.zhonglz.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhonglz.commons.base.BaseController;
import com.zhonglz.model.SysBaseSet;
import com.zhonglz.util.result.ResultUtils;
import com.zhonglz.util.tools.DataGrid;
import com.zhonglz.util.tools.ObjectUtils;


/***
 * SysBaseSetController 系统配置
 * @author zhonglz
 * @date 2019年12月24日
 */
@Controller
@RequestMapping("/sys/baseSet")
public class BaseSetController extends BaseController {

	private static Logger logger = LoggerFactory.getLogger(BaseSetController.class);
	
	/***
	 * 分页查询系统配置列表
	 * @param sysBaseSet
	 * @param startTime
	 * @param endTime
	 * @param pageNumber 第几页
	 * @param pageSize 每页显示多少行数据
	 * @param req
	 * @return
	 */
	@ResponseBody
    @RequestMapping("selectListByData")
    public DataGrid selectListByData(String setName,
    		@RequestParam(defaultValue="") String startTime,
    		@RequestParam(defaultValue="") String endTime,
    		@RequestParam(defaultValue = "1") int pageNumber,
			@RequestParam(defaultValue = "10") int pageSize) {
    	DataGrid dataGrid = null;
		PageHelper.startPage(pageNumber, pageSize);
		// 封装查询条件参数
		Map<String, Object> mapParam = new HashMap<String, Object>();
		if(!startTime.equals("")&&startTime!=null){
			startTime+=" 00:00:00";
			mapParam.put("startTime",startTime);
		}
		if(!endTime.equals("")&&endTime!=null){
			endTime+=" 23:59:59";
			mapParam.put("endTime",endTime);
		}
		if(ObjectUtils.isNotEmpty(setName)) {
			mapParam.put("setName", setName);
		}
		
		List<SysBaseSet> selectBaseSetList=sysBaseSetService.selectListByData(mapParam);
		PageInfo<SysBaseSet> info = new PageInfo<SysBaseSet>(selectBaseSetList);
		
		// 封装结果集
		dataGrid = new DataGrid(info.getTotal(),selectBaseSetList,info.getPages(),info.getPageNum(),ResultUtils.CODE_SUCCESS);
    	return dataGrid;
	}
	
	/***
	 * 根据id查询出配置的详细信息
	 * @param sysSetId
	 * @return
	 */
	@ResponseBody
    @RequestMapping("selectBaseSetById")
	public SysBaseSet selectBaseSetById(Integer sysSetId) {
		return sysBaseSetService.selectBaseSetById(sysSetId);
	}
	
	/***
	 * 保存配置信息
	 * @return
	 */
	@ResponseBody
    @RequestMapping("saveBaseSetInfo")
	public ResultUtils saveBaseSetInfo(SysBaseSet sysBaseSet) {
		return sysBaseSetService.saveBaseSetInfo(sysBaseSet);
	}
	
	/***
	 * 删除配置信息
	 * @param sysSetId
	 * @return
	 */
	@ResponseBody
    @RequestMapping("deleteBaseSetInfo")
	public ResultUtils deleteBaseSetInfo(Integer sysSetId) {
		return sysBaseSetService.deleteBaseSetInfo(sysSetId);
	}
	
}
